//package com.hexiang.shardingsphere.sharding.algorithm;
//
//import com.ctrip.framework.apollo.Config;
//import com.ctrip.framework.apollo.ConfigService;
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
//import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
//import java.util.ArrayList;
//import java.util.Collection;
//
//@Component
//public class UserPreciseShardingAlgorithm implements PreciseShardingAlgorithm<String> {
//    private static final String NO_SHARDING_TABLE_NAME = "t_user";
//
//    private static final String USRE_SHARDING_SWITCH = "user.sharding.switch";
//
//    private static final String USRE_SHARDING_SWITCH_OFF = "off";
//
//    private final Config config = ConfigService.getConfig("jdbc");
//
//    @Override
//    public String doSharding(Collection<String> tableNames, PreciseShardingValue<String> preciseShardingValue) {
//        //不分片实现
//        if (USRE_SHARDING_SWITCH_OFF.equals(config.getProperty(USRE_SHARDING_SWITCH, USRE_SHARDING_SWITCH_OFF))) {
//            return NO_SHARDING_TABLE_NAME;
//        }
//        // 分片实现
//        if (!StringUtils.isEmpty(preciseShardingValue)) {
//            String shardingValue = preciseShardingValue.getValue();
//            int index = getIndex(shardingValue);
//            for (String name : tableNames) {
//                if (name.endsWith(index + "")) {
//                    return name;
//                }
//            }
//
//        }
//
//        return null;
//    }
//    private int getIndex(String uid) {
//        uid = uid.replace("-", "");
//        return Math.abs(uid.hashCode()) % 10;
//    }
//}